﻿using System;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;


namespace Notepad_X.Components
{
    public class OptionsTabControl : TabControl
    {
        private Color _highlightcolor = SystemColors.ControlLight;//Color.FromArgb(255, 255, 255);
        private Color _bordercolor = SystemColors.ControlLight;

        public OptionsTabControl()
        {
            
        }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            Graphics g = e.Graphics;
            //e.Graphics.Clear(SystemColors.Control);
            //g.SmoothingMode = SmoothingMode.AntiAlias;
            //g.CompositingQuality = CompositingQuality.HighQuality;

            //int xIndex=0;
            //for (int t = 0; t <= base.TabCount; t++)
            //{
            //    Rectangle TabRectangle = GetTabRect(t);

            //    Rectangle outerRectangle = new Rectangle(xIndex, 0, TabRectangle.Width - 1, TabRectangle.Height);
            //    Rectangle innerRectangle = new Rectangle(xIndex, 0, TabRectangle.Width - 1, TabRectangle.Height);

            //    if (SelectedIndex == t)
            //    {
            //        Pen pen1 = new Pen(Color.FromArgb(255, _highlightcolor));
            //        Pen pen2 = new Pen(Color.FromArgb(170, _bordercolor));

            //        SolidBrush ob = new SolidBrush(Color.FromArgb(255, _highlightcolor));

            //        g.FillRectangle(ob, outerRectangle);

            //        g.DrawRectangle(pen1, outerRectangle);


            //        g.DrawRectangle(pen2, innerRectangle);
            //    }
            //    else
            //    {
            //        Pen pen1 = new Pen(Color.FromArgb(100, _highlightcolor));
            //        //Pen pen2 = new Pen(Color.FromArgb(100, 255, 255, 255));
            //        Pen pen2 = new Pen(Color.FromArgb(170, _bordercolor));

            //        SolidBrush ob = new SolidBrush(Color.FromArgb(100, _highlightcolor));

            //        g.FillRectangle(ob, outerRectangle);

            //        g.DrawRectangle(pen1, outerRectangle);

            //        g.DrawRectangle(pen2, innerRectangle);
            //    }

            //    //if ((intOverIndex != -1) && intOverIndex != SelectedIndex && t== intOverIndex)
            //    //{

            //    //    Pen pen1 = new Pen(Color.FromArgb(150, _highlightcolor));
            //    //    //Pen pen2 = new Pen(Color.FromArgb(100, 255, 255, 255));
            //    //    Pen pen2 = new Pen(Color.FromArgb(170, _bordercolor));


            //    //    SolidBrush ob = new SolidBrush(Color.FromArgb(160, _highlightcolor));

            //    //    g.FillRectangle(ob, outerRectangle);

            //    //    g.DrawRectangle(pen1, outerRectangle);

            //    //    g.DrawRectangle(pen2, innerRectangle);

            //    //    intOverIndex = -1;
            //    //    Console.Write(t);
            //    //}

            //    SolidBrush Brush = new SolidBrush(this.ForeColor);
            //    RectangleF rf = new RectangleF(xIndex, TabRectangle.Height - (TabRectangle.Height / 2), TabRectangle.Width, TabRectangle.Height / 2);
            //    StringFormat sf = new StringFormat();
            //    sf.Alignment = StringAlignment.Center;
            //    sf.LineAlignment = StringAlignment.Center;

            //    g.DrawString(TabPages[t].Text, this.Font, Brush, rf, sf);
            //    if (base.ImageList != null)
            //    {
            //        Image img = base.ImageList.Images[TabPages[t].ImageIndex];

            //        RectangleF imgRec = new RectangleF((xIndex + (TabRectangle.Width / 2)) - (img.Width / 2), (TabRectangle.Height / 3) - (img.Height / 2), img.Width, img.Height);
            //        g.DrawImage(img, imgRec);
            //    }


            //    xIndex += TabRectangle.Width;

            //}



        }

        //protected override void OnMouseMove(MouseEventArgs e)
        //{
        //    Console.WriteLine("({0},{1})", e.X, e.Y);
        //    base.OnMouseMove(e);


        //    int SelectedIndex;

        //    TabPage tp = GetTabPageByTab(e.Location);
        //    if (tp != null)
        //    {
        //        SelectedIndex = base.TabPages.IndexOf(tp);

        //        if (SelectedIndex != intOverIndex)
        //        {
        //            intOverIndex = SelectedIndex;
        //            //Invalidate();
        //            Update();
        //            Console.WriteLine("Update index {0} last index {1}", intOverIndex, SelectedIndex);
        //        }
        //    }
        //    else
        //    {
        //        intOverIndex = -1;
        //    }            
        //}
        //protected override void OnMouseLeave(EventArgs e)
        //{
        //    intOverIndex = -1;
        //    base.OnMouseLeave(e);
        //}


        public TabPage GetTabPageByTab(Point pt)
        {
            TabPage tp = null;

            for (int i = 0; i < TabPages.Count; i++)
            {
                if (GetTabRect(i).Contains(pt))
                {
                    tp = TabPages[i];
                    break;
                }
            }

            return tp;
        }

        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            //base.OnPaintBackground(pevent);
            pevent.Graphics.Clear(SystemColors.ControlLight);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            //base.OnPaint(e);
            e.Graphics.Clear(SystemColors.ControlLight);
        }
    }
}
